﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Infrastructure.Core.IOC;
using SMG.Application.DTO.Program;
using SMG.ServiceContract.Migration;
using SMG.ServiceContract.Program;
using ManageForm.Model;

namespace ManageForm
{
    public partial class PlayMonitor : Form
    {
        //绑定gridview
        IPlayService playService = ServiceLocator.Instance.Resolve<IPlayService>();

        public PlayMonitor()
        {
            InitializeComponent();
        }

        private void PlayMonitor_Load(object sender, EventArgs e)
        {
            this.dgvImgText.AutoGenerateColumns = false;
            Bind();
        }

        private void Bind()
        {
            IChannelService channelService = ServiceLocator.Instance.Resolve<IChannelService>();
            //查询频道列表
            var channels = channelService.QueryChannelAll();
            //绑定treeview
            foreach (ChannelDto channerl in channels)
            {
                TreeNode tn = new TreeNode();
                tn.Text = channerl.ChannelName;
                tn.Tag = channerl.ChannelId;

                TreeNode Ntn1 = new TreeNode();
                Ntn1.Text = "图文单";
                Ntn1.Tag = 0;
                TreeNode Ntn2 = new TreeNode();
                Ntn2.Text = "模板";
                Ntn2.Tag = 1;
                TreeNode Ntn3 = new TreeNode();
                Ntn3.Text = "模板组";
                Ntn3.Tag = 2;
                TreeNode Ntn4 = new TreeNode();
                Ntn4.Text = "素材";
                Ntn4.Tag = 3;
                tn.Nodes.Add(Ntn1);
                tn.Nodes.Add(Ntn2);
                tn.Nodes.Add(Ntn3);
                tn.Nodes.Add(Ntn4);

                TreeNode NNtn1 = new TreeNode("图片");
                TreeNode NNtn2 = new TreeNode("视频");
                TreeNode NNtn3 = new TreeNode("文字");
                TreeNode NNtn4 = new TreeNode("音频");
                Ntn4.Nodes.Add(NNtn1);
                Ntn4.Nodes.Add(NNtn2);
                Ntn4.Nodes.Add(NNtn3);
                Ntn4.Nodes.Add(NNtn4);

                tvwPlay.Nodes.Add(tn);
            }
        }

        private void tvwPlay_Click(object sender, EventArgs e)
        {
            //查询图表列表
            if (tvwPlay.Parent.Tag != null)
            {
                var plays = playService.QueryPlayByPage(tvwPlay.Parent.Tag.ToString(), tvwPlay.Tag.ToString(), 1, 10);
                dgvImgText.DataSource = plays;
            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void tvwPlay_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvwPlay.SelectedNode != null)
            {
                if (tvwPlay.SelectedNode.Parent != null && tvwPlay.SelectedNode.Parent.Tag != null && tvwPlay.SelectedNode.Tag != null)
                {
                    var plays = playService.QueryPlayByPage(tvwPlay.SelectedNode.Parent.Tag.ToString(), tvwPlay.SelectedNode.Tag.ToString(), 1, 10);
                    var playModels = new List<PlayViewModel>();
                    if (plays.Data != null && plays.Data.Any()) {
                        var index = 1;
                        foreach (var play in plays.Data) {
                            var model = new PlayViewModel(play);
                            model.Index = index;
                            playModels.Add(model);
                            index++;
                        }
                    }
                    dgvImgText.DataSource = playModels;
                }
            }
        }



    }
}
